﻿using CID.Domain.Development;
using CID.Domain.Operations;
using CID.Domain.Users;
using NHibernate;
using System.Collections.Generic;

namespace CID.Domain.Persistence.Tests.Development
{
    static class DataProvider
    {
        private static class ReleaseConstants
        {
            public const string Name = "ReleaseName";
            public const string Description = "ReleaseDescription";
        }

        #region Component
        public static Component CreateComponent(ISession session, IServerRole requiredServerRole, IUser responsible, string name = "ComponentName", string description = "ComponentDescription")
        {
            return CreateComponent(name, description, Operations.DataProvider.GetServerRole(session, requiredServerRole), Users.DataProvider.GetUser(session, responsible));
        }

        public static Component CreateComponent(string name, string description, IServerRole requiredServerRole, IUser responsible)
        {
            return new Component(name, description, requiredServerRole, responsible);
        }

        public static Component GetComponent(ISession session, IComponent componentData)
        {
            return session.Get<Component>(componentData.Id);
        }
        #endregion

        #region Version
        public static Version GetVersion(ISession session, IVersion versionData)
        {
            return session.Get<Version>(versionData.Id);
        }

        public static Version[] GetVersions(ISession session, IVersion[] versionsData)
        {
            var versions = new List<Version>();
            foreach (IVersion versionData in versionsData)
                versions.Add(GetVersion(session, versionData));

            return versions.ToArray();
        }
        #endregion

        #region Release
        public static Release CreateRelease(ISession session, IUser responsible, params IVersion[] versions)
        {
            return CreateRelease(session, responsible, "Release Name", "Release Description", versions);
        }

        public static Release CreateRelease(ISession session, IUser responsible, string name, string description, params IVersion[] versions)
        {
            return CreateRelease(name, description, Users.DataProvider.GetUser(session, responsible), GetVersions(session, versions));
        }

        public static Release CreateRelease(string name, string description, IUser responsible, params IVersion[] versions)
        {
            var result = new Release(name, description, responsible);
            result.SetActive();
            foreach (IVersion version in versions)
                result.AddVersion(version);
            return result;
        }

        public static Release GetRelease(ISession session, IRelease releaseData)
        {
            return session.Get<Release>(releaseData.Id);
        }
        #endregion
    }
}
